export default {
    state: {
        isCollapse: false,
        tabList: [
            {
                path: '/',
                name: 'home',
                label: '首页',
                icon: 'home'
            }
        ],
        currentMenu: null
    },
    mutations: {
        collapseMenu(state) {
            state.isCollapse = !state.isCollapse;
        },
        selectMenu(state, value) {
            if(value.name !== 'home') {
                state.currentMenu = value;
                if(!state.tabList.find(item => item.name === value.name)) {
                    state.tabList.push(value);
                }
            } else {
                state.currentMenu = state.tabList[0];
            }
        },
        deleteMenu(state, value) {
            if(value.name === state.currentMenu.name) {
                let index = state.tabList.findIndex(ele => ele.name === value.name) - 1;
                state.currentMenu = state.tabList[index];
            }

            if(value.name !== 'home') {
                state.tabList.forEach((ele, i) => {
                    if(ele.name === value.name) {
                        state.tabList.splice(i,1);
                    }
                });
            } 
            
        }
    }
}